import config from './config.js'

var arr = [{
		name: 'navigateTo'
	},
	{
		name: 'redirectTo'
	},
	{
		name: 'reLaunch'
	}
]



function initApp() {
	for (var i = 0; i < arr.length; i++) {
		uni.addInterceptor(arr[i].name, {
			invoke(e) {
				const AccessToken = uni.getStorageSync('AccessToken')
				var url = e.url.split('?')[0];
				let notNeed = config.whiteList.includes(url)
				if (notNeed == false) {
					if (!AccessToken) {
						uni.showToast({
							icon:'none',
							title: '请登录',
							duration: 2000
						});
						return false
					}
				} else {
					return true
				}
			},
			fail(err) {
				console.log('interceptor-fail', err)
			}
		})
	}
}

export default {
	initApp
}
